package com.day1.bg;

public class HashCode {
    public static void main(String[] args) {
        Person p1 = new Person("张三", 18);
        Person p2 = new Person("张三", 18);
        System.out.println(p1.hashCode());
        System.out.println(p2.hashCode());
        System.out.println(p1.equals(p2));
        System.out.println(p1.hashCode() == p2.hashCode());
        System.out.println(p1 == p2);
    }
}
class Person {
    private String name;
    private int age;
    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }
    /*@Override
    public int hashCode() {
        return name.hashCode() + age;
    }*/
    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Person) {
            Person p = (Person)obj;
            return name.equals(p.name) && age == p.age;
        }
        return false;
    }
}
